#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <linux/in.h>
//#include <netinet/in.h>
#include "haruhi.h"
int main()
{
	int fd;
	struct sockaddr_in dest;
	char buffer[128];

	fd = socket(PF_INET, SOCK_STREAM, 0);

	bzero(&dest, sizeof(dest));
	//memset(&dest, 0, sizeof(dest));

	dest.sin_family = PF_INET;
	dest.sin_port = htons (9090);
	inet_aton("127.0.0.1", &dest.sin_addr);

	dest.sin_addr.s_addr = INADDR_ANY;

	bind(fd, (struct sockaddr *)&dest, sizeof(dest));

	listen(fd, 20);

	while(1)
	{
		int amber_fd;
		struct sockaddr_in amber_addr;
		int addrlen = sizeof(amber_addr);

		amber_fd = accept(fd, (struct sockaddr*)&amber_addr, &addrlen);
	
		sprintf(buffer, "Hello Amber %d\n", amber_fd);

		send(amber_fd, buffer, sizeof(buffer), 0);

		close(amber_fd);
	}

	close(fd);

	return 0;

}
